﻿/***************************************************************************
//* Foxit Software Inc.
//* Copyright(C) 2005-2012, all rights reserved.
//*
//* The following code is copyrighted and contains proprietary information
//* and trade secrets of Foxit Software Inc.                                                      *
***************************************************************************/

/**
* 主窗口
*/

define(function (require, exports, module) {
    var CPDF_DocView = require('./PDFDocView');
    var CImgPageViewRender = require('./ImgPageViewRender');
    var LayoutInfo = require('./LayoutInfo');
    /**
     * Mainframe view.
     * @class Mainframe view.
     * @constructor
     * @param {String} MainFrameID  ID of the mainframe div.
     * @param {String} leftPanelID  ID of the navigation panel.
     * @param {String} topPanelID   ID of the top panel.
     * @param {FXREADER.Data.CPDF_Document} pPDFDoc 	 PDF document object.
     * @param {FXREADER.PDFView.CImgPageViewRender} pPageViewRender render object.
 	* @param {FXREADER.PDFView.LayoutInfo} layoutInfo 	 layout infomation.
 	* @param {FXREADER.CReaderApp} pReaderApp 	 App object.
     * @return a mainframe view
     */
    FXREADER.PDFView.CMainFrame = function (MainFrameID, leftPanelID, topPanelID,bottomPanelID, pPDFDoc, pPageViewRender, layoutInfo, pReaderApp) {
        var _pDocView = null,
              _LeftPanelID = leftPanelID,
              _TopPanelID = topPanelID,
              _BottomPanelID = bottomPanelID,
              _LeftPanel = null,
              _MainFrameID = MainFrameID,
              _pReaderApp = pReaderApp,
              _pPageViewRender = pPageViewRender;

        _Construct();
        //构造函数;
        function _Construct() {
            _pDocView = new CPDF_DocView(pPDFDoc, pPageViewRender, MainFrameID, layoutInfo, _pReaderApp);
            var jqMainFrame = $("#" + _MainFrameID);
            _pDocView.SetDocViewWidth(jqMainFrame.width());
            _pDocView.SetDocViewHeight(jqMainFrame.height());
            _pDocView.Init();
        }

        /**
         * @description Get the doc view.
         * @return {FXREADER.PDFView.CPDF_DocView} doc view object.
         */
        this.GetDocView = function () {
            return _pDocView;
        };
        /**
         * @description Get the ID of the mainframe div.
         * @return {String} ID of the mainframe div.
         */
        this.GetMainFrameID = function () {
            return _MainFrameID;
        };
        /**
         * @description Get the ID of the navigation panel div.
         * @return {String} ID of the navigation panel div.
         */
        this.GetLeftPanelID = function () {
            return _LeftPanelID;
        };
        /**
         * @description Get the ID of the top panel div.
         * @return {String} ID of the top panel div.
         */
        this.GetTopPanelID = function () {
            return _TopPanelID;
        };

        this.OnResize = function () {
            var jqMainFrame = $("#" + _MainFrameID);
            //下面两句主要是为了兼容ie7
			if(!(FXREADER.Environment.mobile || FXREADER.Environment.iOS))
            {
				jqMainFrame.width($(window).width());
				jqMainFrame.height($(window).height());
			}

            var nMainFrameWidth = jqMainFrame.width();
            var nMainFrameHeight = jqMainFrame.height();
            var jqLeftPanel = $("#" + _LeftPanelID);
            var jqTopPanel = $("#" + _TopPanelID);
            var jqBottomPanel = $("#"+_BottomPanelID);
            jqTopPanel.width(nMainFrameWidth);
            jqBottomPanel.width(nMainFrameWidth);
            var nTopPanelHeight = jqTopPanel.is(":hidden") ? 0 : jqTopPanel.height();
            var nBottomPanelHeight = jqBottomPanel.is(":hidden") ? 0 : jqBottomPanel.height();
            var nLeftPanelHeight = nMainFrameHeight - nTopPanelHeight - nBottomPanelHeight;
            var nLeftPanelWidth = jqLeftPanel.is(":hidden") ? 0 : jqLeftPanel.innerWidth();
            jqLeftPanel.css({ top: nTopPanelHeight, height: nLeftPanelHeight });
            if (_pDocView != null) {
                var nDocViewWidth = nMainFrameWidth - nLeftPanelWidth;
                var nDocViewHeight = nMainFrameHeight - nTopPanelHeight - nBottomPanelHeight;
                var nDocViewOffsetLeft = nLeftPanelWidth;
                var nDocViewOffsetTop = nTopPanelHeight;
                //大小没改变;
                if (nDocViewWidth == _pDocView.GetDocViewWidth() && nDocViewHeight == _pDocView.GetDocViewHeight()
                    && nDocViewOffsetLeft == _pDocView.GetDocViewOffsetLeft() && nDocViewOffsetTop == _pDocView.GetDocViewOffsetTop())
                    return;

                _pDocView.OnSize(nDocViewWidth, nDocViewHeight, nDocViewOffsetLeft, nDocViewOffsetTop);
            }
        };

    };

    return FXREADER.PDFView.CMainFrame;
});